
import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { ListAdvanced } from 'weaver-mobile-page';
import { Tools } from 'weaver-mobile';
const getLabel = Tools.getLabel;

@inject('meetingSearchStore')
@withRouter
@observer
export default class Search extends Component {

  componentWillMount() {
    this.onSearch();
  }

  componentDidMount() {
    window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(16424,'查询会议') })
    // const { listAd,dataFetchOptions } = this.props.meetingSearchStore;
    // listAd.getData(dataFetchOptions);
    this.onSearch();
  }

  componentWillReceiveProps(nextProps){
    let prePathName = this.props.location.pathname
    let curPathName = nextProps.location.pathname
    if(curPathName&&curPathName!==prePathName){
      if(curPathName == "/calendar/search"){
        window.em && window.em.checkJsApi('changeTitle') && window.em.changeTitle({ title: getLabel(16424,'查询会议') })
      }
    }
  }
  onSearch = () => {
    const { listAd,dataFetchOptions } = this.props.meetingSearchStore;
    const { searchAdvancedStore, listViewStore, searchParams } = listAd;
    // 搜索框等搜索数据
    let params = { ...searchParams};
    // 获取高级搜索参数
    // if (searchAdvancedStore) {
      const { formParams } = searchAdvancedStore.form;
      params = { ...formParams,ismobile:1 };
    // }
    // 清除列表数据
    listViewStore.clearData();
    // 带参数请求列表数据
    listAd.getData({...dataFetchOptions, params });
  }

  render() {
    const { meetingSearchStore } = this.props;
    const { listAd, dataFetchOptions,conditionFetchOptions } = meetingSearchStore;
    return (
      <div>
        <ListAdvanced
          store={listAd}
          hasAdvanceSerach
          rowKey="ID"
          searchKey="names"
          dataFetchOptions={dataFetchOptions}
          conditionFetchOptions={conditionFetchOptions}
          showCheck={false}
          buttonGroupData={[{
            key: 'submit',
            text: getLabel(826, '确定'),
            onClick: this.onSearch,
            type: 'primary',
          }]}
          onSearch={this.onSearch}
          onRowClick={(a)=>{this.viewDetail(a.id)}}
        />
      </div>
    );
  }

  viewDetail = (params) => {
    const { history, } = this.props;
    sessionStorage.setItem('type','view')
    history.push({pathname:"/calendar/detail",query:{meetingid:params}});
  }

}